<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    论坛：<div></div>
    <textarea name="" id="" cols="30" rows="10"></textarea>
    <button>发布</button>
    <script>
        /*
            str.replace(regexp|substr, newSubStr|function)

            需求1：需要贴吧发布的信息中关键字进行过滤
         */
        const divObj = document.querySelector("div");
        const textareaObj = document.querySelector("textarea");
        const btnObj = document.querySelector("button");

        btnObj.addEventListener("click", function () {
            /* 
                g:表示全局替换
                i：表示忽略大小写
            */
            divObj.innerHTML = textareaObj.value.replace(/卧槽/g, "**");
        })

        /*
            需求2：通过正则实现如下需求
                日期：2022-11-12
                想输出结果为：12-11-2022
         */
        const re1 = /(\d{4})-(\d{2})-(\d{2})/;
        const strDate = "2025-07-08";
        /* 
            分别代表对应括号的内容
            $3 = (\d{2})
            $2 = (\d{2})
            $1 = (\d{4})
         */
        const result1 = strDate.replace(re1, "$3-$2-$1");
        console.log(result1);

        //方式二
        const result2 = strDate.replace(re1, function () {
            return RegExp.$3 + "-" + RegExp.$2 + "-" + RegExp.$1
        });
        console.log(result2);
    </script>
</body>

</html>